import Toast from 'vant-weapp/toast/toast';
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      info:{
        name:"",
        idcard:"",
        age:""
      },
      columns: ['养老院1', '养老院2', '养老院3', '养老院4', '养老院5'],
      show:false,
  
  },
  onChange(e) {
    const param = e.currentTarget.dataset.name; //字段名 
   
    const value = e.detail; //值 
    const key=`info.${param}`;
    this.setData({
      [key]:value
    })
  },
  toShow(){
    this.setData({
      show:true
    })
  },
  onCancel(){
    this.setData({
      show:false
    })
  },
  submit(){
    console.log(this.data.info.name)
    if(this.data.info.name&&this.data.info.age&&this.data.info.idcard)
    db.collection("oldmanlist").add({
      data:{
        name:this.data.info.name,
        id_card:this.data.info.id_card,
        age:this.data.info.age
      }
    }).then(res=>{
      console.log(res)
    })
    wx.navigateBack({
      delta: 1,
      success: function (e) {
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad(); // 刷新数据
      }
    });
    
  },
  onConfirm(event){
    const { picker, value, index } = event.detail;
    console.log(value)
    this.setData({
      show:false,
      "info.yly":value
    })
  }
 
})